package com.training.dao.impl.liuyong;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.training.dao.liuyong.IAjaxDao;
import com.training.pojo.chengshu.UUser;

public class AjaxDaoImpl extends HibernateDaoSupport implements IAjaxDao {

	//验证用户登录
	@SuppressWarnings("unchecked")
	public boolean checkLogin(String username, String password) {
		HibernateTemplate tmp = this.getHibernateTemplate();
		System.out.println(tmp);
		String hql = "FROM UUser AS uu WHERE uu.uname = ? AND uu.upass = ?";
		List<UUser> list = (List<UUser>)tmp.find(hql, username, password);
		boolean result = false;
		if (list.size() > 0) {
			result = true;
		}
		return result;
	}

	//获取指定用户名和密码的用户信息
	@SuppressWarnings("unchecked")
	public UUser getUser(String username, String password) {
		HibernateTemplate tmp = this.getHibernateTemplate();
		String hql = "FROM UUser AS uu WHERE uu.uname = ? AND uu.upass = ?";
		List<UUser> list = (List<UUser>)tmp.find(hql, username, password);
		return list.get(0);
	}
}
